package com.sgl.blog.controller.blog;

import com.sgl.blog.service.ArticleService;
import com.sgl.blog.service.LabelService;
import com.sgl.blog.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @标题：
 * @内容：
 * @作者： 宋志豪
 */
@Controller
@RequestMapping("blog")
public class PublicationsController {

    @Resource
    private ArticleService articleService;

    @Resource
    private TypeService typeService;

    @Resource
    private LabelService labelService;

    @GetMapping("publications")
    public String publicationsPage(Model model){
        model.addAttribute("sgl_type",typeService.findAll());
        model.addAttribute("sgl_label", labelService.findAll());
        model.addAttribute("sgl_article", null);
        model.addAttribute("sgl_isUpdate",true);
        return "markdown";
    }

    @GetMapping("update/{id}")
    public String update(@PathVariable("id") Integer id, Model model){
        model.addAttribute("sgl_type",typeService.findAll());
        model.addAttribute("sgl_label", labelService.findAll());
        model.addAttribute("sgl_article", articleService.findBlogById(id));
        model.addAttribute("sgl_isUpdate",false);
        return "markdown";
    }
}
